import { Behaviour, HitTestScript, getGameObjectById, GameObject, core } from "../gameengine";
import { user } from "../user";
import { ColliderSystem } from "../rect/ColliderSystem";
import { RectCollider, RectColliderType } from "../rect/RectCollider";
import { yuxie } from "../data";

export class yuxieshitou extends Behaviour {
    ui1: GameObject;

    protected onStart() {

            

    }

    protected onUpdate(advancedTime: number) {

        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
            const collider = this.displayObject.getScript(RectCollider);
            const nextCollider = {
                left: collider.left + -4,
                right: collider.right + 4,
                top: collider.top + -4,
                bottom: collider.bottom + 4
            }
            const hitTestResult1 = colliderSystem.check(nextCollider, RectColliderType.MAINROLE);

            if (hitTestResult1){
                console.log("1")
                    if (!this.ui1) {
                        this.ui1 = core.createPrefab(yuxie);
                        const scene = getGameObjectById("UIScene");
                        scene.addChild(this.ui1);
                    }

                
            }



        if (user.removerock2 == true) {
            this.displayObject.parent.removeChild(this.displayObject);

        }

    }



}